<template>
  <div class="GoldRecord">
    <div class="GoldCoinRechargeBalance">
      <div class="GoldCoinRechargeBg">
        <div class="login_div">
          <p></p>
          <img @click="gouWenhao" src="../assets/image/wenhao.png" alt="" />
        </div>
        <div class="one">
          <img src="../assets/image/jinbi.png" alt="" />
          <span>{{ gold }}</span>
        </div>
      </div>
      <!-- <div class="two">
          <p @click="getJinbi">领金币</p>
        </div> -->
    </div>
    <div class="list" v-if="list.length != 0">
      <vantList v-model="loading" :finished="finished" @load="getlist">
        <div class="list-item" v-for="item in list" :key="item" :title="item">
          <div class="left">
            <div class="mark">{{ item.mark }}</div>
            <div class="time">{{ item.createTime | time }}</div>
          </div>
          <div class="right">
            <span class="red" v-if="item.gold.indexOf('-') != -1">{{
              item.gold
            }}</span>
            <span v-else>{{ "+" + item.gold }}</span>
          </div>
        </div>

        <div class="finished" slot="finished" style="text-align: center">
          没有更多了哦
        </div>
      </vantList>
    </div>
    <div class="kongBox" v-else>
      <img src="../assets/image/xingqiu.png" alt="" />
      <div class="txt">暂时没有记录哦～</div>
    </div>
  </div>
</template>

<script>
import { List } from "vant";
import { orderCoinRecord, userUserinfo } from "../api/reply";
export default {
  components: {
    vantList: List,
  },
  data() {
    return {
      gold: "0",
      list: [],
      loading: false,
      finished: false,
      page: 1,
      pageSize: 10,
      total: "",
    };
  },
  methods: {
    //点击问号
    gouWenhao() {
      this.$router.push("/CommonProblem");
    },
    async getlist() {
      this.loading = true;
      const res = await orderCoinRecord({
        page: this.page,
        pageSize: this.pageSize,
      });
      if (res.code == 0) {
        this.loading = false;
        this.list.push(...res.data.list);
        this.total = res.data.count;
        if (this.list.length == this.total) {
          this.finished = true;
        } else {
          this.page++;
        }
      } else {
        this.loading = false;
      }
    },
    // 获取个人信息
    async getUserInfo() {
      const res = await userUserinfo();
      if (res.code == 0) {
        this.gold = res.data.goldCoin;
      }
    },
  },
  created() {
    if (this.$route.query.token) {
      localStorage.setItem("access_token", this.$route.query.token);
    }
    this.getlist();
    this.getUserInfo();
  },
  filters: {
    //时间转化
    time: (value) => {
      if (!value) return "";
      let value1 = value * 1000;
      var date = new Date(value1);
      var YY = date.getFullYear() + "-";
      var MM =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hh =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var mm =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var ss =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return YY + MM + DD + " " + hh + mm + ss;
    },
  },
};
</script>

<style lang="less" scoped>
.GoldRecord {
  // background: #19162a;
  padding: 0px 25px;
  min-height: 100vh;
  .GoldCoinRechargeBalance {
    width: 100%;
    padding-top: 30px;
    .GoldCoinRechargeBg {
      background: url("../assets/image/jinbiBg.png") no-repeat;
      background-size: 100%;
      width: 100%;
      height: 98px;
      color: white;
      .login_div {
        display: flex;
        justify-content: space-between;
        padding: 5px;
        font-size: 12px;
        img {
          width: 16px;
          height: 16px;
        }
      }
      .one {
        padding-top: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
          width: 16px;
          height: 16px;
          margin-right: 5px;
        }
        span {
          font-size: 20px;
        }
      }
      .two {
        display: flex;
        justify-content: flex-end;
        p {
          width: 65px;
          height: 25px;
          line-height: 25px;
          text-align: center;
          background: rgba(255, 225, 255, 0.15);
          margin: 10px;
          border-radius: 25px;
          font-size: 12px;
        }
      }
    }
  }
  .list {
    padding-top: 50px;
    padding-bottom: 50px;
    .list-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-bottom: 20px;
      .left {
        .mark {
          color: #333333;
          font-size: 16px;
        }
        .time {
          color: #999999;
          font-size: 14px;
        }
      }
      .right {
        font-size: 16px;
        // font-weight: 700;
        .red {
          color: #ff5050;
        }
        span {
          color: #333333;
        }
      }
      .finished {
        text-align: center;
      }
    }
  }
  .kongBox {
    padding: 100px;
    .txt {
      padding-top: 15px;
      text-align: center;
      color: #62606e;
      font-size: 14px;
      font-weight: 600;
    }
  }
}
</style>